<template>
	<view class="container">
		<view class="title">拍摄/上传您的二代身份证</view>
		<view class="item" @click="toUpload(1)">
			<image v-if="driverRegisterInfo.idcardMainImg" :src="driverRegisterInfo.idcardMainImg" class="bg"></image>
			<image v-else src="@/static/img/shenfenzheng-1.png" class="bg"></image>
			<view class="tips-box" v-if="!driverRegisterInfo.idcardMainImg">
				<image class="xiangji" src="@/static/img/xiangji.png"></image>
				<view class="tips">拍摄/上传手持身份证人面像</view>
			</view>
		</view>
		<view class="item" @click="toUpload(2)">
			<image v-if="driverRegisterInfo.idcardFrontImg" :src="driverRegisterInfo.idcardFrontImg"  class="bg"></image>
			<image v-else src="@/static/img/shenfenzheng-2.png"  class="bg"></image>
			<view class="tips-box" v-if="!driverRegisterInfo.idcardFrontImg">
				<image class="xiangji" src="@/static/img/xiangji.png"></image>
				<view class="tips">拍摄/上传身份证人像面</view>
			</view>
		</view>
		<view class="item" @click="toUpload(3)">
			<image v-if="driverRegisterInfo.idcardBackImg" :src="driverRegisterInfo.idcardBackImg"  class="bg"></image>
			<image v-else src="@/static/img/shenfenzheng-3.png"  class="bg"></image>
			<view class="tips-box" v-if="!driverRegisterInfo.idcardBackImg">
				<image class="xiangji" src="@/static/img/xiangji.png"></image>
				<view class="tips">拍摄/上传身份证国徽面</view>
			</view>
		</view>
		<view v-if="driverRegisterInfo 
		&& driverRegisterInfo.idcardMainImg 
		&& driverRegisterInfo.idcardFrontImg 
		&& driverRegisterInfo.idcardBackImg" class="btn-submit-box">
			<view class="btn-submit" @click="clickIdcardConfirm">
				确认并提交
			</view>
		</view>
		
		<uni-popup ref="message" type="message">
			<uni-popup-message :type="msgType" :message="msgText" :duration="3000"></uni-popup-message>
		</uni-popup>
	</view>
</template>

<script>
	import {driverRegSubmit} from '@/api/api.js';
	
	export default {
		data() {
			return {
				driverRegisterInfo:{
					idcardMainImg:null,
					idcardFrontImg:null,
					idcardBackImg:null
				},
				msgType:'',
				msgText:''
			}
		},
		onLoad() {
			let p = uni.getStorageSync('driverRegisterInfo');
			if(p){
				this.driverRegisterInfo.idcardMainImg = p.idcardMainImg;
				this.driverRegisterInfo.idcardFrontImg = p.idcardFrontImg;
				this.driverRegisterInfo.idcardBackImg = p.idcardBackImg;
			}
		},
		methods: {
			clickIdcardConfirm(){
				driverRegSubmit(this.driverRegisterInfo).then(res=>{
					if(res && res.data){
						this.msgType = 'success';
						this.msgText = '提交成功';
						this.$refs.message.open();
						uni.navigateBack();
					}
					else {
						this.msgType = 'error';
						this.msgText = '提交失败';
						this.$refs.message.open();
					}
				}).catch(res=>{
					this.msgType = 'error';
					this.msgText = '提交失败';
					this.$refs.message.open();
				})
			},
			toUpload(n){
				let that = this;
				that.$util.uploadImageOne({
					url: 'upload/image',
					name: 'multipart',
					model: "driver",
					pid: 0,
					count: 1
				}, function(res) {
					if(n===1){
						that.driverRegisterInfo.idcardMainImg = res;
					}
					else if(n===2){
						that.driverRegisterInfo.idcardFrontImg = res;
					}
					else{
						that.driverRegisterInfo.idcardBackImg = res;
					}
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.container{
		padding-top: 30rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		gap: 30rpx;
		.title{
			font-size: 33rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			color: #333333;
		}
		.item{
			position: relative;
			width: 558rpx;
			height: 335rpx;
			border: 3rpx solid #6FC65E;
			border-radius: 21rpx;
			overflow: hidden;
			.bg{
				width: 558rpx;
				height: 335rpx;
				z-index: 9;
			}
			.tips-box{
				position: absolute;
				top: 0;
				z-index: 99;
				width: 100%;
				height: 100%;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				background-color: rgba(0, 0, 0, 0.5);
				gap: 26rpx;
				.xiangji{
					width: 82rpx;
					height: 67rpx;
					background: #3D3D3D;
				}
				.tips{
					font-size: 29rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
				}
			}
		}
	}
	.btn-submit-box{
		position: fixed;
		left: 30rpx;
		right: 30rpx;
		bottom: 30rpx;
	}
	.btn-submit{
		width: 100%;
		height: 94rpx;
		background: #6FC65E;
		border-radius: 47rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 38rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
	}
</style>
